{extend name="base"/}
{block name="css"}
<link rel="stylesheet" href="/static/backend/css/goods_order.css?t=8">
<style>
body{background: none !important;}
.thum img {width: 100px;height: 100px;}
.layui-icon.layedit-tool-face{display: none;}
</style>
{/block}
{block name="content"}
   <form id="myForm" class="layui-form" style="width:80%;" enctype="multipart/form-data">
       <div class="layui-form-item">
           <label class="layui-form-label">分类名称</label>
           <div class="layui-input-block">
               <select name="cat_id" id="cat_id" class="con">
                   {volist name='select_info' id='vo'}
                   <option value="{$vo.id}">{$vo.coupon_name}</option>
                   {/volist}
               </select>
           </div>
       </div>
       <div class="layui-form-item">
           <label class="layui-form-label">优惠券面值</label>
           <div class="layui-input-block">
               <input type="text" class="layui-input dataIntegral" name="amount" value="" lay-verify="required"  placeholder="请输入">
           </div>
       </div>
       <div class="layui-form-item">
           <label class="layui-form-label">满多少时可用（分类为满减时必填）</label>
           <div class="layui-input-block">
               <input type="text" class="layui-input dataIntegral" name="full_amount" value="" lay-verify="required"  placeholder="分类为满减时必填">
           </div>
       </div>
       <div class="layui-form-item">
           <label class="layui-form-label">数量</label>
           <div class="layui-input-block">
               <input type="text" class="layui-input dataIntegral" name="number" value="" lay-verify="required"  placeholder="请输入">
           </div>
       </div>
       <div class="layui-form-item">
           <label class="layui-form-label">过期时间</label>
           <div class="layui-input-block">
               <input type="text" class="layui-input" id="time1" name="expired_time" style="width: 40%;">
           </div>
       </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                 <input type="button"  lay-submit="" lay-filter="addAbout" value="{:lang('确认保存')}" class="" id="submit" style="width: 90px;height: 38px;text-align: center;line-height: 38px;border: none; background: #009688; color: #fff;border-radius: 2px;">
            </div>
        </div>
    </form>
{/block}
{block name="js"}
<script type="text/javascript" src="/static/backend/js/jquery.form.js"></script>
<script type="text/javascript" src="/static/backend/js/swiper.min.js"></script>
<script type="text/javascript" src="/static/backend/layui/layui.js?t=10"></script>
<script type="text/javascript" src="/static/backend/layer/layer.js?t=10"></script>
<script>
    layui.use('laydate', function(){
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#time1' //指定元素
            ,type:'datetime'
        });
    });
    $(function () {
        layui.config({
            base: "/static/admin/js/"
        }).use(['form', 'layer', 'jquery', 'layedit', 'upload'], function () {
            var form = layui.form,
                    layer = parent.layer === undefined ? layui.layer : parent.layer,
                    upload = layui.upload,
                    layedit = layui.layedit,
                    $ = layui.jquery;
            //创建一个编辑器
            var editIndex = layedit.build('LAY_demo1', {
                uploadImage: {
                    url: '/backend/goods/uploadImg/'
                    ,type: 'post'
                }
            });
            form.on("submit(addAbout)", function (data) {
                data.field.content = layedit.getContent(editIndex);

                var formdom = $('#myForm')[0]
                        ,formdata = new FormData(formdom);
                $.ajax({
                    url: '/backend/coupon/doadd_coupon',
                    type: 'POST',
                    data: formdata,
                    processData: false, // jQuery不要去处理发送的数据
                    contentType: false, // jQuery不要去设置Content-Type请求头
                    success: function(res) {
                        console.log(res);
                        if(res.code==1){
                            layer.msg(res.msg, {
                                time: 2000 //2秒关闭（如果不配置，默认是3秒）
                            }, function(){
                                setTimeout(parent.location.reload(),3000);
                            });
                            //刷新父页面

                        }else{
                            top.layer.msg(res.msg);
                        }
                    }

                });


                return false;
            })

        });

    })
</script>
{/block}